/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.jsimplemarket.wicket.pages;

import com.googlecode.jsimplemarket.model.Firma;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import com.googlecode.jsimplemarket.service.GenericService;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;


/**
 *
 * @author Alexandru.Codescu
 */
public class FirmaViewPage extends DefaultViewPage {
    //@SpringBean(name = "defaultGridAction")
    //private DefaultGridAction<Firma> gridAction;
    
    @SpringBean(name = "genericService")
    private GenericService<Firma> firmaService;
	    
    
    public FirmaViewPage() {
        init();
    }
    
    public String printStandardDate(Date dataGame) {
		return new SimpleDateFormat("dd.MM.yyyy HH:mm").format(dataGame);
	}
    
    private class FirmaView extends ListView<Firma> {

        public FirmaView(String id, List<Firma> data) {
            super(id, data);
        }

        @Override
        protected void populateItem(ListItem<Firma> li) {
            final Firma firma = li.getModelObject();
            li.add(new Label("cif", firma.getCif()));
            li.add(new Label("denumire", firma.getDenumire()));
            li.add(new Label("contact", firma.getDateContact()));
            li.add(new Label("adaugat", printStandardDate(firma.getDataCreare())));
            
            Link editLink = new Link("editLink") {
                @Override
                public void onClick() {
                    setResponsePage(new FirmaEditPage((Long) firma.getId()));
                }
            };
            li.add(editLink);

        }
    }

    private void init() {
        
    	List<Firma> clienti = firmaService.getList(Firma.class, null, null);
        FirmaView firmaView = new FirmaView("firmaView", clienti);
        add(firmaView);
        
        Link addLink = new Link("addLink") {
            @Override
            public void onClick() {
                setResponsePage(new FirmaEditPage());
            }
        };
        add(addLink);        
        
    }
}
